package fr.umlv.escapeir.ship;

import java.awt.Image;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.MathUtils;
import org.jbox2d.common.Vec2;

import fr.umlv.escapeir.GameWorld;
import fr.umlv.escapeir.game.Ripper;
import fr.umlv.escapeir.game.WorldActor;
import fr.umlv.escapeir.painter.ExplosionPainter;
import fr.umlv.escapeir.weapon.Weapon;

public class EnnemyShip extends PolygonShip {
	
	private static final int GROUP_INDEX = GameWorld.WALL_INDEX;
	private static final float ANGLE = MathUtils.PI;
	private static final int EXPLOSION_SIZE = 15;
	private static final int EXPLOSION_DURATION = 2;
	
	private EnnemyShip(GameWorld gameWorld, float x, float y,
			PolygonShape shape, final Image image,
			final Vec2 imageTopLeft, final Vec2 imageBottomRight) {
		super(gameWorld, x, y, ANGLE, shape, image, imageTopLeft, imageBottomRight, GROUP_INDEX);
	}
	
	static EnnemyShip createInWorld(GameWorld world, float x, float y,
			PolygonShape shape, final Image image,
			final Vec2 imageTopLeft, final Vec2 imageBottomRight) {
		
		EnnemyShip act = new EnnemyShip(world, x, y, shape, image, imageTopLeft, imageBottomRight);
		act.setBody(world.addActor(act, act.getBdef()));
		act.getBody().createFixture(act.getFdef());
		act.getBody().m_userData = act;
		return act;
	}

	@Override
	public Type type() {
		return WorldActor.Type.ENNEMY;
	}

	@Override
	public void touch(WorldActor actor) {
		setPainter(new ExplosionPainter(getBody(), EXPLOSION_DURATION, EXPLOSION_SIZE));
		setBehavior(new Ripper(getWorld(), this, getBody(), EXPLOSION_DURATION));
	}

	@Override
	public void addWeapon(Weapon weapon) {
		setWeapon(weapon);
		fire(0);
	}

}
